package com.qdaily.ui.data;

import android.os.Parcel;
import android.os.Parcelable;
import com.qdaily.ui.net.entity.UserCenterEntity;

/**
 * 用戶行為，包含一系列關於用戶的信息。
 * Created with IntelliJ IDEA.
 * User: Felix
 * Date: 4/3/15
 * Time: 16:54
 * QQ:74104
 * Email:lovejiuwei@gmail.com
 */
public class UserInformation implements Parcelable {
    private String userIcon = "";
    private String userName = "";
    private String userDescription = "";
    private String userEmail = "";
    private String userPhone = "";
    private String cookie = "";
    private int userMessageCount = 0;//消息数量
    private UserSocial userSocial = new UserSocial();

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.userIcon);
        dest.writeString(this.userName);
        dest.writeString(this.userDescription);
        dest.writeString(this.userEmail);
        dest.writeString(this.userPhone);
        dest.writeString(this.cookie);
        dest.writeInt(this.userMessageCount);
        dest.writeParcelable(this.userSocial, 0);
    }

    public UserInformation() {
    }

    private UserInformation(Parcel in) {
        this.userIcon = in.readString();
        this.userName = in.readString();
        this.userDescription = in.readString();
        this.userEmail = in.readString();
        this.userPhone = in.readString();
        this.cookie = in.readString();
        this.userMessageCount = in.readInt();
        this.userSocial = in.readParcelable(UserSocial.class.getClassLoader());
    }

    public static final Creator<UserInformation> CREATOR = new Creator<UserInformation>() {
        public UserInformation createFromParcel(Parcel source) {
            return new UserInformation(source);
        }

        public UserInformation[] newArray(int size) {
            return new UserInformation[size];
        }
    };

    public String getUserIcon() {
        return userIcon;
    }

    public void setUserIcon(String userIcon) {
        this.userIcon = userIcon;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserDescription() {
        return userDescription;
    }

    public void setUserDescription(String userDescription) {
        this.userDescription = userDescription;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }

    public String getCookie() {
        return cookie;
    }

    public void setCookie(String cookie) {
        this.cookie = cookie;
    }

    public int getUserMessageCount() {
        return userMessageCount;
    }

    public void setUserMessageCount(int userMessageCount) {
        this.userMessageCount = userMessageCount;
    }

    public UserSocial getUserSocial() {
        return userSocial;
    }

    public void setUserSocial(UserSocial userSocial) {
        this.userSocial = userSocial;
    }

    /**
     * 用戶社交屬性
     * Created with IntelliJ IDEA.
     * User: Felix
     * Date: 4/3/15
     * Time: 17:07
     * QQ:74104
     * Email:lovejiuwei@gmail.com
     */
    public static class UserSocial implements Parcelable {
        private boolean bindQQ = false;
        private boolean bindWechat = false;
        private boolean bindTwitter = false;
        private boolean bindWeibo = false;

        public boolean isBindQQ() {
            return bindQQ;
        }

        public void setBindQQ(boolean bindQQ) {
            this.bindQQ = bindQQ;
        }

        public boolean isBindWechat() {
            return bindWechat;
        }

        public void setBindWechat(boolean bindWechat) {
            this.bindWechat = bindWechat;
        }

        public boolean isBindTwitter() {
            return bindTwitter;
        }

        public void setBindTwitter(boolean bindTwitter) {
            this.bindTwitter = bindTwitter;
        }

        public boolean isBindWeibo() {
            return bindWeibo;
        }

        public void setBindWeibo(boolean bindWeibo) {
            this.bindWeibo = bindWeibo;
        }

        @Override
        public String toString() {
            return "UserSocial{" +
                    "bindQQ=" + bindQQ +
                    ", bindWechat=" + bindWechat +
                    ", bindTwitter=" + bindTwitter +
                    ", bindWeibo=" + bindWeibo +
                    '}';
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeByte(bindQQ ? (byte) 1 : (byte) 0);
            dest.writeByte(bindWechat ? (byte) 1 : (byte) 0);
            dest.writeByte(bindTwitter ? (byte) 1 : (byte) 0);
            dest.writeByte(bindWeibo ? (byte) 1 : (byte) 0);
        }

        public UserSocial() {
        }

        private UserSocial(Parcel in) {
            this.bindQQ = in.readByte() != 0;
            this.bindWechat = in.readByte() != 0;
            this.bindTwitter = in.readByte() != 0;
            this.bindWeibo = in.readByte() != 0;

        }

        public static final Creator<UserSocial> CREATOR = new Creator<UserSocial>() {
            public UserSocial createFromParcel(Parcel source) {
                return new UserSocial(source);
            }

            public UserSocial[] newArray(int size) {
                return new UserSocial[size];
            }
        };
    }

    /**
     * 服务器模板翻译成本地
     *
     * @param userCenterEntity
     * @return
     */
    public UserInformation translation(UserCenterEntity userCenterEntity) {
        //账户相关的才会返回cookie。
        this.setCookie(userCenterEntity.getMeta().getCookie());
        this.setUserDescription(userCenterEntity.getResponse().getDescription());
        this.setUserEmail(userCenterEntity.getResponse().getEmail());
        this.setUserIcon(userCenterEntity.getResponse().getFace());
        this.setUserMessageCount(userCenterEntity.getResponse().getMessage());
        this.setUserName(userCenterEntity.getResponse().getUsername());
        this.setUserPhone(userCenterEntity.getResponse().getPhone());
        this.getUserSocial().setBindQQ(userCenterEntity.getResponse().isQq());
        this.getUserSocial().setBindTwitter(userCenterEntity.getResponse().isTwitter());
        this.getUserSocial().setBindWechat(userCenterEntity.getResponse().isWechat());
        this.getUserSocial().setBindWeibo(userCenterEntity.getResponse().isWeibo());
        this.setUserSocial(getUserSocial());
        return this;
    }
}
